def barok(xuanlu,paizi,jiezou=120):
    qian = getlu(xuanlu,paizi,1)     #一题段音
    hou = getlu(xuanlu,paizi,2)      #二题段音
    qiantime = gettime(paizi,1)      #一提时间
    houtime = gettime(paizi,2)       #二题时间
    
    qiandiba = tishen(qian,-12)    #一提低八
    qiantiwu = tishen(qian,7)     #一题五度
    qiandiwu = tishen(qiandiba,7)   #一题低八度提五度
    
    houdiba = tishen(hou,-12)       #二题低八
    houtiwu = tishen(hou,7)         #二题提五度

    qiandao1 = getdao(qian,houtiwu[-1])    #倒影

    qiandao2 = getdao(qian,qiandao1[-1]-2)   #倒影
    qiandao3 = getdao(qian,qiandao2[-1]-2)   #倒影
    qiandao4 = getdao(qian,qiandao3[-1]-2)   #倒影
    qiantier = tishen(qiandiba,2)          #一提低八高大二度
    
    a = qiandao4[-1] - hou[0]
    houzhong = tishen(hou,qiandao4[-1] - hou[0])            #二题，最后音为上个音
    
    qiandao5 = getdao(qian,houzhong[-1])  #第二次倒影
    qiandao6 = getdao(qian,qiandao5[-1]+2)  #第二次倒影
    qiandao7 = getdao(qian,qiandao6[-1]+2)  #第二次倒影
    qiandao8 = getdao(qian,qiandao7[-1]+2)  #第二次倒影
    
    
    #开始
    #二声部（和弦的）
    myin(qian,qiantime,time=jiezou,tr=track2)
    myin(qiandiba,qiantime,time=jiezou,tr=track2)
    myin(qiantiwu,qiantime,time=jiezou,tr=track2)
    myin(qiandiwu,qiantime,time=jiezou,tr=track2)
    
    myin(qian,qiantime,time= jiezou,tr=track3)
    myin(qiandiba,qiantime,time=jiezou,tr=track3)
    myin(qiantiwu,qiantime,time=jiezou,tr=track3)
    myin(qiandiwu,qiantime,time=jiezou,tr=track3)
    myin(qiandao1,qiantime,time=jiezou,tr=track3)
    myin(qiandao2,qiantime,time=jiezou,tr=track3)
    #一声部
    myin(qian,qiantime,time=jiezou)
    myin(qiandiba,qiantime,time=jiezou)
    myin(qiantiwu,qiantime,time=jiezou)
    myin(qiandiwu,qiantime,time=jiezou)
    
    myin(qiandao1,qiantime,time=jiezou,du="dasan")
    myin(qiandao2,qiantime,time=jiezou,du="daliu")
    myin(qiandao3,qiantime,time=jiezou,chord="dasan",note="wu")
    myin(qiandao4,qiantime,time=jiezou,chord="dasi",note="zhong")
    
    #二声部
    myin(qiantier,qiantime,time= jiezou,tr=track2)
    myin(hou,houtime,time= jiezou,tr=track2)
    myin(qiantier,qiantime,time= jiezou,tr=track3)
    myin(hou,houtime,time= jiezou,tr=track3)
    myin(qiandao5,qiantime,time= jiezou,tr=track3)
    myin(qiandao6,qiantime,time= jiezou,tr=track3)
    
    #返回一声部
    myin(qiantier,qiantime,time= jiezou)
    myin(hou,houtime,time= jiezou)
    
    
    #倒影
    myin(qiandao5,qiantime,time= jiezou,du="daliu")
    myin(qiandao6,qiantime,time= jiezou,du="dasan")
    myin(qiandao7,qiantime,time= jiezou,chord="xiaosan",note="wu")
    myin(qiandao8,qiantime,time= jiezou,chord="dasi",note="zhong")
    
    myin(qiandao5,qiantime,time= jiezou,tr=track2)
    myin(qiandao6,qiantime,time= jiezou,tr=track2)
    myin(qiandao7,qiantime,time= jiezou,tr=track2)
    myin(qiandao8,qiantime,time= jiezou,tr=track2)
    myin(qiandao5,qiantime,time= jiezou,tr=track3)
    myin(qiandao6,qiantime,time= jiezou,tr=track3)
    myin(qiandao7,qiantime,time= jiezou,tr=track3)
    myin(qiandao8,qiantime,time= jiezou,tr=track3)
    #二声部
    myin(qian,qiantime,time= jiezou,tr=track4) #先重复，占第二声部的位
    myin(hou,houtime,time= jiezou,tr=track4)
    myin(houdiba,houtime,time= jiezou,tr=track4)
    myin(houtiwu,houtime,time= jiezou,tr=track4)
    
    myin(qiandao1,qiantime,time=jiezou,tr=track4)
    myin(qiandao2,qiantime,time=jiezou,tr=track4)
    myin(qiandao3,qiantime,time=jiezou,tr=track4)
    myin(qiandao4,qiantime,time=jiezou,tr=track4)

    myin(houzhong,houtime,time=jiezou,tr=track4)

    
  
    xxxx = [1,1,1]
    lastyin = jieyin(xuanlu)
    lastpai = [1,xxxx,xxxx,xxxx,xxxx,xxxx,xxxx,1,0.5,1.5,3]
    myin(lastyin,lastpai,time=jiezou)
    a = lastyin[-1] + 1
    b = [[]]
    b[0].append(a)
    b[0].append(a+4)
    b[0].append(a+7)
    myin(b,[[6,6,6]],chord = "dasan",time=jiezou)
import random

def creatyin(diao="do"):
    if type(diao) == str:
        if diao[0] == "#":
            diao = num(diao[1]) + 1
        elif diao[0] == "b" and len(diao) == 2:
            diao = num(diao[1]) + 1
        else:
            diao = num(diao)
    times = random.randint(6,17)
    yinfu = [diao]
    di = diao - 2
    gao = diao + 8
    for i in range(times):
        a = random.randint(di,gao)
        yinfu.append(a)
    yinfu.append(diao+7)
    return yinfu
    
def creatpai(yinfu):
    a = []
    le = len(yinfu)
    c = random.randint(3,le-2)
    d = le - c
    for i in range(c):
        a.append(1)
    e = c / d
    if int(e) == e:
        e = int(e)
    for i in range(d):
        a.append(e)
    return a